using System.Windows.Documents;
using System.Windows.Input;
using Bookvar.ObjectModel.Actions;
using Bookvar.UI.Commands;

namespace Bookvar.UI.ViewModel
{
    public partial class NotesWindowViewModel
    {
        private class SaveNotesCommand : CommandModel
        {
            private readonly NotesWindowViewModel viewModel;

            public SaveNotesCommand(NotesWindowViewModel viewModel)
                : base( BookvarCommands.SaveNotes )
            {
                this.viewModel = viewModel;
            }

            protected internal override void OnExecute( object sender, ExecutedRoutedEventArgs e )
            {
                TextRange newNotes = e.Parameter as TextRange;

                if ( newNotes != null )
                {
                    var changeNotesAction = new ChangeTopicAction( viewModel.Topic ) { Notes = newNotes };
                    ActionService.Execute( changeNotesAction );
                }
            }

            protected internal override void OnCanExecute( object sender, CanExecuteRoutedEventArgs e )
            {
                e.CanExecute = true;
                e.Handled = true;
            }
        }
    }
}